package com.back.end.vo;

import com.back.end.enums.ResultCode;
import lombok.Data;

/**
 * @author HT
 * @Feature: API返回统一结果集
 */

@Data
public class Result<T> {
    /**
     * 错误码.
     */
    private Integer code;

    /**
     * 提示信息.
     */
    private String message;

    /**
     * 具体的内容.
     */
    private T data;

    private String token;

    public static Result success(Object object) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(object);
        return result;
    }

    public static Result loginSuccess(Object object, String token) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(object);
        result.setToken(token);
        return result;
    }


    public static Result error(Integer code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Result error(ResultCode resultCode) {
        Result result = error(resultCode.getCode(), resultCode.getMessage());
        return result;
    }

}
